package core;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import towers.Bunker;
import towers.Cannon;
import towers.MissileLauncher;
import towers.NuclearBase;
import towers.Plasmagun;

/**
 * @author Arno de Jager
 *
 */
public class Controller implements ActionListener {
	
	private View view;
	private Model model;
	private Mouse mouse;
	
	public Controller(Model m) {
		this.mouse = new Mouse( m );
		
		view = new View(m, this);
		this.model = m;
		
		model.addObserver( view );
	}
	
	public View getView() {
		return this.view;
	}

	public void actionPerformed(ActionEvent e) {
		// Bouw torens
		if ( e.getActionCommand().equals( "Cannon" )) {
			this.mouse.setSelectedItem( new Cannon( null ) );
		}
		else if ( e.getActionCommand().equals( "Bunker" )) {
			this.mouse.setSelectedItem( new Bunker( null ) );
		}
		else if ( e.getActionCommand().equals( "Missile Launcher" )) {
			this.mouse.setSelectedItem( new MissileLauncher( null ) );
		}
		else if ( e.getActionCommand().equals( "Nuclear Base" )) {
			this.mouse.setSelectedItem( new NuclearBase( null ) );
		}
		else if ( e.getActionCommand().equals( "Plasmagun" )) {
			this.mouse.setSelectedItem( new Plasmagun( null ) );
		}
		
		// Etcetera
		else if ( e.getActionCommand().equals( "Next Wave" )) {
			model.nextWave();
		}
		else if ( e.getActionCommand().equals( "Repair" )){
			model.repair(this.mouse.getSelectedItem());
		}
		else if ( e.getActionCommand().equals( "Sell" )){
			model.sell(this.mouse.getSelectedItem());
		}
		else if ( e.getActionCommand().equals( "Pause" )){
			model.togglePause();
		}
	}

	/**
	 * @return the mouse
	 */
	public Mouse getMouse() {
		return mouse;
	}
}